<?php
namespace App\Services;
use App\Models\Rewards;
use App\DTOS\Admin\RewardsSearchDTO;
// 奖励
class RewardsService
{
    /**
    * @var  \Illuminate\Database\Eloquent\Builder
    */
    private Rewards $model;

    public function __construct()
    {
        $this->model = new Rewards;
        global $gameArea;
        $this->model->setGameArea($gameArea);
    }

    public function paginate(RewardsSearchDTO $DTO)
    {
        $perPage = $DTO->getLimit();
        $page = $DTO->getPage();
        $model = $this->model;
        /**条件判断**/
        $type = $DTO->getType();
        if ($type){
            $model = $model->where('type',$type);
        }
        return $model->orderBy("id")->paginate($perPage,'*','page',$page);
    }

    public function deleteById($id)
    {
        $this->model->where('id',$id)->delete();
    }

    public function deleteByIds($ids)
    {
        if (empty($ids)) return;
        $this->model->whereIn('id',$ids)->delete();
    }
    public function getById($id)
    {
        return $this->model->where('id',$id)->first();
    }
}
